﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using QuanLyBanHang.DataConnection;
using System.Windows.Forms;

namespace QuanLyBanHang.QuerySQL
{
    class ClassKhachhang
    {
        Connect conn = new Connect();
        //Show
        public DataTable ShowKH()
        {
            DataTable tb = new DataTable(); ;
            try
            {
                string sql = "select *from KHACHHANG";
                tb = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
        public DataTable ShowMAKH(string makh)
        {
            DataTable tb = new DataTable(); ;
            try
            {
                string sql = "select *from KHACHHANG where MAKH like '%" + makh + "%'";
                tb = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
        public DataTable ShowTKH(string tenkh)
        {
            DataTable tb = new DataTable(); ;
            try
            {
                string sql = "select *from KHACHHANG where HOTEN like N'%" + tenkh + "%'";
                tb = conn.getTable(sql);
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
            return tb;
        }
        //Them sua xoa
        public void ThemKH(string makh, string tenkh,string dc, string sdt)
        {
            try
            {
                string sql = "insert into KHACHHANG values('" + makh + "',N'" + tenkh + "',N'" + dc + "','" + sdt + "')";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Thêm thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi :" +e.Message);
            }
        }
        public void SuaKH(string makh, string makh1, string tenkh, string dc, string sdt)
        {
            try
            {
                string sql = "update KHACHHANG set MAKH = '"+makh1+"',HOTEN =N'" + tenkh + "',DIACHIKH =N'" + dc + "',SODTKH ='" + sdt +"' where MAKH = '" + makh + "' ";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Sửa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi :" + e.Message);
            }
        }
        public void XoaKH(string makh)
        {
            try
            {
                string sql = "delete KHACHHANG where MAKH = '" + makh + "'";
                conn.ExcuteQuerySql(sql);
                MessageBox.Show("Xóa thành công !!!");
            }
            catch (Exception e)
            {
                MessageBox.Show("Lỗi: " + e.Message);
            }
        }
    }
}
